package com.sgcc.pms.tocs.common.result;

import lombok.Getter;

@Getter
public class WrapperedResult<T> {

	private boolean successful = false;
	private int code;
	private String message;
	private T data;
	
	private WrapperedResult() {}
	private WrapperedResult(T data) {
		this.successful = true;
		this.data = data;
		this.code = 200;
	}
	
	public static WrapperedResult<Void> ok() {
		return okMsg(null);
	}
	
	public static WrapperedResult<Void> okMsg(String message) {
		WrapperedResult<Void> result = new WrapperedResult<>();
		result.successful = true;
		result.code = 200;
		result.message = message;
		return result;
	}
	
	public static<E> WrapperedResult<E> ok(E data) {
		WrapperedResult<E> result = new WrapperedResult<>(data);
		return result;
	}
	
	public static<E> WrapperedResult<E> error(String message) {
		WrapperedResult<E> result = new WrapperedResult<>();
		result.message = message;
		result.code = 500;
		return result;
	}
	
}
